import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  {
    path: '/basicArchives',
    component: Layout,
    redirect: '/basicArchives/from',
    name: 'BasicArchives',
    meta: { title: '基础档案', icon: '档案' },
    children: [
      {
        path: 'persionInformation',
        name: 'persionInformation',
        component: () => import('@/views/modules/basicArchives/persionInformation/index'),
        meta: { title: '个人信息', icon: 'user' }
      },
      {
        path: 'merchantFiles',
        name: 'merchantFiles',
        component: () => import('@/views/modules/basicArchives/merchantFiles/index'),
        meta: { title: '商户档案', icon: '商户档案' }
      },
      {
        path: 'paymentRules',
        name: 'paymentRules',
        component: () => import('@/views/modules/basicArchives/paymentRules/index'),
        meta: { title: '支付规则', icon: '规则引擎' }
      }
    ]
  },

  {
    path: '/reconciliationManagement',
    component: Layout,
    redirect: '/reconciliationManagement/menu1',
    name: 'ReconciliationManagement',
    meta: { title: '对账管理', icon: '对账管理' },
    hidden: false,
    children: [
      {
        path: 'unionPayReconciliation',
        name: 'unionPayReconciliation',
        component: () => import('@/views/modules/reconciliationManagement/unionPayReconciliation'),
        meta: { title: '支付渠道对账', icon: '银行对账单' }
      },
      {
        path: 'bankOfChinaReconciliation',
        name: 'bankOfChinaReconciliation',
        component: () => import('@/views/modules/reconciliationManagement/bankOfChinaReconciliation'),
        meta: { title: '支付渠道对账', icon: '银行对账单' }
      }
     
    ]
  },

  {
    path: '/systemSetting',
    component: Layout,
    redirect: '/systemSetting/table',
    name: 'SystemSetting',
    meta: { title: '系统设置', icon: '系统设置' },
    children: [
      {
        path: 'configurationManagement',
        name: 'configurationManagement',
        component: () => import('@/views/modules/systemSetting/configurationManagement'),
        meta: { title: '配置管理', icon: '配置管理' }
      },
      {
        path: 'APIManagement',
        name: 'APIManagement',
        component: () => import('@/views/modules/systemSetting/APIManagement'),
        meta: { title: 'API管理', icon: 'API管理2' }
      },
      {
        path: 'menuManagement',
        name: 'menuManagement',
        component: () => import('@/views/modules/systemSetting/menuManagement'),
        meta: { title: '菜单管理', icon: '菜单管理' }
      },
      {
        path: 'userManagement',
        name: 'userManagement',
        component: () => import('@/views/modules/systemSetting/userManagement'),
        meta: { title: '用户管理', icon: '用户管理' }
      },
      {
        path: 'departmentManagement',
        name: 'departmentManagement',
        component: () => import('@/views/modules/systemSetting/departmentManagement'),
        meta: { title: '部门管理', icon: '部门管理' }
      },
      {
        path: 'regionManagement',
        name: 'regionManagement',
        component: () => import('@/views/modules/systemSetting/regionManagement'),
        meta: { title: '区域管理', icon: '区域管理' }
      },
      {
        path: 'roleManagement',
        name: 'roleManagement',
        component: () => import('@/views/modules/systemSetting/roleManagement'),
        meta: { title: '角色管理', icon: '角色管理' }
      },
      {
        path: 'dictionaryManagement',
        name: 'dictionaryManagement',
        component: () => import('@/views/modules/systemSetting/dictionaryManagement'),
        meta: { title: '字典管理', icon: '字典管理' }
      },
      {
        path: 'canZhaoManagement',
        name: 'canZhaoManagement',
        component: () => import('@/views/modules/systemSetting/canZhaoManagement'),
        meta: { title: '参照管理', icon: '参照管理' }
      },
      {
        path: 'treeManagement',
        name: 'treeManagement',
        component: () => import('@/views/modules/systemSetting/treeManagement'),
        meta: { title: '树表管理', icon: 'tree' }
      },
      {
        path: 'organizationalManagement',
        name: 'organizationalManagement',
        component: () => import('@/views/modules/systemSetting/organizationalManagement'),
        meta: { title: '机构管理', icon: '机构管理' }
      }
    ]
  },

  {
    path: '/paymentManager',
    component: Layout,
    redirect: '/paymentManager/unionPayManagement',
    name: 'PaymentManager',
    meta: { title: '支付管理', icon: '支付管理' },
    children: [
      {
        path: 'unionPayManagement',
        name: 'unionPayManagement',
        component:  () => import('@/views/modules/paymentManager/unionPayManagement/'),
        meta: { title: '银联支付管理', icon: '支付银联' },
        children: [
          {
            path: 'unionPayLog',
            name: 'unionPayLog',
            component: () => import('@/views/modules/paymentManager/unionPayManagement/unionPayLog/'),
            meta: { title: '报文日志', icon: '日志记录' }
          },
          {
            path: 'unionPayFlow',
            name: 'unionPayFlow',
            component: () => import('@/views/modules/paymentManager/unionPayManagement/unionPayFlow/'),
            meta: { title: '支付流水', icon: '支付流水' }
          }
        ]
      },
      {
        path: 'bankOfChinaManagement',
        name: 'bankOfChinaManagement',
        component:  () => import('@/views/modules/paymentManager/bankOfChinaManagement/'),
        meta: { title: '中行支付管理', icon: '银行' },
        children: [
          {
            path: '/bankOfChinaLog/',
            name: 'bankOfChinaLog',
            component: () => import('@/views/modules/paymentManager/bankOfChinaManagement/bankOfChinaLog'),
            meta: { title: '报文日志', icon: '日志记录' }
          },
          {
            path: '/bankOfChinaFlow/',
            name: 'bankOfChinaFlow',
            component: () => import('@/views/modules/paymentManager/bankOfChinaManagement/bankOfChinaFlow'),
            meta: { title: '支付流水', icon: '支付流水' }
          }
        ]
      }
    ]
  },

  {
    path: '/codeGeneration',
    component: Layout,
    redirect: '/codeGeneration/table',
    name: 'CodeGeneration',
    meta: { title: '代码生成', icon: '代码生成' },
    children: [
      {
        path: 'formDeploy',
        name: 'formDeploy',
        component: () => import('@/views/modules/codeGeneration/formDeploy'),
        meta: { title: '表单配置', icon: '表单配置' }
      },
      {
        path: 'generationScheme',
        name: 'generationScheme',
        component: () => import('@/views/modules/codeGeneration/generationScheme'),
        meta: { title: '生成方案', icon: '生成方案' }
      }
    ]
  },

  {
    path: '/trafficPoliceFiles',
    component: Layout,
    redirect: '/trafficPoliceFiles/table',
    name: 'TrafficPoliceFiles',
    meta: { title: '交警档案', icon: '档案' },
    children: [
      {
        path: 'transactionBill',
        name: 'transactionBill',
        component: () => import('@/views/modules/trafficPoliceFiles/transactionBill'),
        meta: { title: '交易账单', icon: '交易账单' }
      },
      {
        path: 'callbackLog',
        name: 'callbackLog',
        component: () => import('@/views/modules/trafficPoliceFiles/callbackLog'),
        meta: { title: '回调记录', icon: '回调记录' }
      },
      {
        path: 'transactionLog',
        name: 'transactionLog',
        component: () => import('@/views/modules/trafficPoliceFiles/transactionLog'),
        meta: { title: '交易日志', icon: '日志记录' }
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
